<template>
    <view>
        <anilSeat :title="movieInfo.name" :info="timeData+'|'+movieInfo.filmTypes" :room-name="officeInfo.hallName" :max="max" :seatData="dataList"
            @confirm="getInfo">
        </anilSeat>
    </view>

</template>

<script>
import anilSeat from '../components/anil-seat.vue'
// import {getSeat,createOrder} from "@/api/film.js"
import config from "@/utils/config.js"
import dataArr from "@/utils/dataArray.js"
import { getCinemaSeatList } from "@/api/movie.js"
export default {
    components: { anilSeat },
    data() {
        return {
            dataList: [],
            max: 4,
            cinemaId: '',
            movieInfo: {},
            officeInfo: {},
            timeData: "",
            priceList: [],
        }
    },
    onLoad(opt) {
        let _this = this
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('moviceDataFrom', function (data) {
            console.log(JSON.stringify(data), 777777)
            _this.movieInfo = data.data
        })
        let item = JSON.parse(decodeURIComponent(opt.item));
        _this.timeData = config.formattedDate(item.showTime, 0)
        this.officeInfo = item
        const areaData = this.officeInfo.scheduleArea.split(';');
        const priceList = areaData.map(area => {
            const areaValues = area.split(',');
            const areaObject = {};
            areaValues.forEach(pair => {
                const [key, value] = pair.split(':');
                areaObject[key] = value;
            });
            return areaObject;
        });
        this.priceList = priceList;
        this.cinemaId = opt.cinemaId
        this.getData()
        // this.cinemaInfo = JSON.parse(decodeURIComponent(opt.cinemaInfo));

    },
    methods: {
        getData() {
            console.log(this.priceList,"this.priceList111")
            getCinemaSeatList({ show_id: this.officeInfo.showId }).then(res => {
                console.log(res.data, "传过来的座次")
                this.max = res.data.restrictions
                let data = res.data.seats ? res.data.seats : []
                if (data.length > 0) {
                    let arrat = []
                    data.forEach(item => {
                        let pai = Number(item.seatId.split('#')[0])
                        let lie = Number(item.seatId.split('#')[1])
                        let real_price = this.priceList.find(it => it.area == item.area) ? (this.priceList.find(it => it.area == item.area).price / 100).toFixed(2) : 0
                        let price = this.priceList.find(it => it.area == item.area) ? ((this.priceList.find(it => it.area == item.area).price / 100) * (this.officeInfo.ratio / 100)).toFixed(2) : 0
                        arrat.push({
                            YCoord: item.rowNo,
                            XCoord: item.columnNo,
                            SeatCode: item.seatId,
                            Status: item.status == 'N' ? 0 : 1,
                            real_price: real_price,
                            Price: price,
                            RowNum: pai,
                            ColumnNum: lie,
                            seatName: item.seatNo,
                            love_status: item.lovestatus,
                            area: item.area
                        })
                    })
                    setTimeout(() => {
                        this.$loading()
                        this.dataList = arrat
                        console.log(this.dataList, "arrat,756")
                        this.$forceUpdate()
                        this.$hideLoading()
                    }, 200);
                }
            })

        },
        getInfo(e) {
            console.log(e, "eeee88")
            let array = []
            let data_json = []
            let sum = 0;
            e.forEach(item => {
                array.push({
                    seatId: item.SeatCode,
                    seatName: item.RowNum + '排' + item.ColumnNum + '座'
                })
                data_json.push({
                    row_sn: item.RowNum,
                    column_sn: item.ColumnNum,
                    status: item.status,
                    name: item.name,
                    love_status: item.love_status,
                    net_price: item.real_price,
                    area: item.area
                })
                sum += Number(item.Price)
            })
            let prm = {
                showId: this.officeInfo.showId,
                cinemaId: this.cinemaId,
                price: sum,
                showInfor: array,
                movie_info: this.movieInfo,
                officeInfo: this.officeInfo,
                data_json: data_json
            }
            prm.movie_info.cinemaName = this.officeInfo.cinemaName
            prm.movie_info.hallName = this.officeInfo.hallName
            console.log(prm, "prm")

            uni.navigateTo({
                url: '/pagesB/movie/confirm-order?dataList=' + encodeURIComponent(JSON.stringify(prm))
            })
        },
    }
}
</script>

<style lang="less">
</style>
